package entity;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Enumeration;

public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        //获取用户的令牌
        //将令牌再封装到头文件中
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        Enumeration<String> headerNames = requestAttributes.getRequest().getHeaderNames();
        while (headerNames.hasMoreElements()){
            String headerKey = headerNames.nextElement();
            String headerValue = requestAttributes.getRequest().getHeader(headerKey);
            System.out.println(headerKey+":"+headerValue);

            //将请求头信息封装到头中
            RequestTemplate header = template.header(headerKey, headerValue);
        }

    }
}
